using System;
using System.Collections.Generic;
using System.Xml;

namespace Studio.Game.GameBox
{
    /// <summary>
    /// Sentence of AgentScript Parser
    /// </summary>
    public class AgentScriptSentence
    {
        private Keywords_V1 _Keyword = Keywords_V1.INVALID;
        /// <summary>
        /// Keyword of this line
        /// </summary>
        public Keywords_V1 Keyword
        {
            get { return _Keyword; }
        }

        private string[] _Params;
        /// <summary>
        /// Parameters are divided by Commas
        /// </summary>
        public string[] Params
        {
            get { return _Params; }
        }

        public AgentScriptSentence(string Sentence)
        {
            LoadSentence(Sentence);
        }

        protected void LoadSentence(string Sentence)
        {
            // Divide keyword by "="
            int DivideIndex = Sentence.IndexOf('=');
            if (DivideIndex > 0)
            {
                string Word = Sentence.Substring(0, DivideIndex).Trim();
                // if keyword recognized ok, retrieve parameters.
                if (true == Keywords<Keywords_V1>.Recognize(Word, ref _Keyword))
                    _Params = Sentence.Substring(DivideIndex + 1).Split(new char[] { ',' },
                        StringSplitOptions.RemoveEmptyEntries);
            }
            else
                _Keyword = Keywords<Keywords_V1>.Recognize(Sentence);
        }

        public AgentScriptSentence(string Format, params object[] args)
        {
            LoadSentence(string.Format(Format, args));
        }

    }
}
